"""
S: a list of n integers
x: another integer
find 2 ele in S whose sum is x
"""
def find2ele(S,x):
    P=[x-s for s in S]
    S.sort()
    P.sort()
    return find_same(P,S,x)

def find_same(P,S,x):
    i=0
    j=0
    while i<len(P) and j<len(S):
        if P[i]==S[j]:
            return P[i],x-S[j]
        elif P[i]>S[j]:
            j=j+1
        else:
            i=i+1
    return None

if __name__=='__main__':
    S=[1,5,2,6,3,4,15,11,12]
    x=17
    print 'S=', S
    print 'x=', x
    print 'result=', find2ele(S,x)
